import {createRouter, createWebHashHistory} from "vue-router"
import LoginPage from '../components/Pages/LoginPage.vue'
import RegisterPage from '../components/Pages/RegisterPage.vue'
import UserPage from '../components/Pages/UserPage.vue'
import UserInfo from '../components/Pages/UserInfo.vue'
import UserChange from '../components/Pages/UserChange.vue'
import UserManagePage from '../components/Pages/UserManagePage'
import RemoteTerminalPage from '../components/Pages/RemoteTerminalPage'
import MenuManagePage from '../components/Pages/MenuManagePage'
import PermissionManagePage from '../components/Pages/PermissionManagePage'
import SessionManagePage from '../components/Pages/SessionManagePage'
import LogManagePage from '../components/Pages/LogManagePage'
const router= createRouter({
    history: createWebHashHistory(),
    routes: [
        {
            path: "/",
            redirect:LoginPage
        },
        {
            path:"/login",
            name: "LoginPage",
            component: LoginPage,
        },
        {
            path:"/register",
            name:"Register",
            component: RegisterPage
        },
        {
            path:"/user",
            name:"UserPage",
            component: UserPage,
            children:[
                {
                    path:"info",
                    name:"UserInfo",
                    component: UserInfo,
                    meta:{show:true}
                },
                {
                    path:"change",
                    name:"UserChange",
                    component: UserChange,
                    meta:{show:true}
                },
                {
                    path:"userManage",
                    name:"UserManagePage",
                    component: UserManagePage,
                    meta:{show:true}
                },
                {
                    path:"remoteTerminal",
                    name:"RemoteTerminal",
                    component: RemoteTerminalPage,
                    meta:{show:true}
                },
                {
                    path:"menuManage",
                    name:"MenuManagePage",
                    component: MenuManagePage,
                    meta:{show:true}
                },
                {
                    path:"permissionManage",
                    name:"PermissionManagePage",
                    component: PermissionManagePage,
                    meta:{show:true}
                },
                {
                    path:"sessionManage",
                    name:"SessionManagePage",
                    component: SessionManagePage,
                    meta:{show:true}
                },
                {
                    path:"logManage",
                    name:"LogManagePage",
                    component: LogManagePage,
                    meta:{show:true}
                },
            ]
        },
        
    ]
})

router.beforeEach((to, from, next) => {
    if (to.meta.show===false) {
        alert('禁止访问')
    //   next({path:"/user"}) // 隐藏该子路由组件，导航到404页面
    } else {
      next(); // 显示该子路由组件
    }
  });

export default router;